//
//  UIButton+Extension.swift
//  01sinablog
//
//  Created by ZhangZiang on 15/12/17.
//  Copyright © 2015年 ZhangZiang. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init(title : String, backImageName : String? = nil, color : UIColor, fontSize : CGFloat, imageName : String? = nil)
    {
        self.init()
        if backImageName != nil
        {
        setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
           
        }
        if imageName != nil
        {
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
        setTitle(title, forState: .Normal)
        
        setTitleColor(color, forState: .Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)

        sizeToFit()
    }
    
    convenience init(imageName : String?, backImageName : String?)
    {
        self.init()
        
        if imageName != nil {
        setImage(UIImage(named: imageName!), forState: .Normal)
        setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)
        }
        
        if backImageName != nil {
        setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: .Highlighted)
        }
        sizeToFit()
    }
}